home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / colloc.cc < prev    next >
C/C++ Source or Header  |  1996-11-03  |  3KB  |  142 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26.  
  27. #include <string>
  28.  
  29. #include "CollocWt.h"
  30.  
  31. #include "defun-dld.h"
  32. #include "error.h"
  33. #include "help.h"
  34. #include "mappers.h"
  35. #include "oct-obj.h"
  36. #include "utils.h"
  37.  
  38. DEFUN_DLD (colloc, args, ,
  39.   "[R, A, B, Q] = colloc (N [, \"left\"] [, \"right\"]): collocation weights")
  40. {
  41.   octave_value_list retval;
  42.  
  43.   int nargin = args.length ();
  44.  
  45.   if (nargin < 1 || nargin > 3)
  46.     {
  47.       print_usage ("colloc");
  48.       return retval;
  49.     }
  50.  
  51.   if (! args(0).is_scalar_type ())
  52.     {
  53.       error ("colloc: first argument must be a scalar");
  54.       return retval;
  55.     }
  56.  
  57.   double tmp = args(0).double_value ();
  58.  
  59.   if (error_state)
  60.     return retval;
  61.  
  62.   if (xisnan (tmp))
  63.     {
  64.       error ("colloc: NaN is invalid as NCOL");
  65.       return retval;
  66.     }
  67.  
  68.   int ncol = NINT (tmp);
  69.   if (ncol < 0)
  70.     {
  71.       error ("colloc: first argument must be non-negative");
  72.       return retval;
  73.     }
  74.  
  75.   int ntot = ncol;
  76.   int left = 0;
  77.   int right = 0;
  78.  
  79.   for (int i = 1; i < nargin; i++)
  80.     {
  81.       if (args(i).is_defined ())
  82.     {
  83.       if (! args(i).is_string ())
  84.         {
  85.           error ("colloc: expecting string argument");
  86.           return retval;
  87.         }
  88.  
  89.       string s = args(i).string_value ();
  90.  
  91.       if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r'))
  92.           || s == "right")
  93.         {
  94.           right = 1;
  95.         }
  96.       else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l'))
  97.            || s == "left")
  98.         {
  99.           left = 1;
  100.         }
  101.       else
  102.         {
  103.           error ("colloc: unrecognized argument");
  104.           return retval;
  105.         }
  106.     }
  107.       else
  108.     {
  109.       error ("colloc: unexpected empty argument");
  110.       return retval;
  111.     }
  112.     }
  113.  
  114.   ntot += left + right;
  115.   if (ntot < 1)
  116.     {
  117.       error ("colloc: the total number of roots must be positive");
  118.       return retval;
  119.     }
  120.   
  121.   CollocWt wts (ncol, left, right);
  122.  
  123.   ColumnVector r = wts.roots ();
  124.   Matrix A = wts.first ();
  125.   Matrix B = wts.second ();
  126.   ColumnVector q = wts.quad_weights ();
  127.  
  128.   retval(3) = q;
  129.   retval(2) = B;
  130.   retval(1) = A;
  131.   retval(0) = r;
  132.  
  133.   return retval;
  134. }
  135.  
  136. /*
  137. ;;; Local Variables: ***
  138. ;;; mode: C++ ***
  139. ;;; End: ***
  140. */
  141.  
  142.